package com.app.micaihu.view.army.dialog

import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import com.app.base.BaseBottomSheetDialogFragment
import com.app.micaihu.R
import com.app.micaihu.view.army.adapter.ArmyHeadListAdapter
import com.app.micaihu.view.bean.ArmyIcon
import kotlinx.android.synthetic.main.army_create_head_dialog.*

/**
 * 创建军团 选择军团头像
 */
class ArmyCreateHeadDialog : BaseBottomSheetDialogFragment() {

    override fun getLayoutId() = R.layout.army_create_head_dialog

    private var onHeadClickListener: OnHeadClickListener? = null

    private val armyHeadListAdapter: ArmyHeadListAdapter by lazy {
        ArmyHeadListAdapter()
    }

    override fun setData() {
        rvHead.layoutManager = GridLayoutManager(context, 3)
        rvHead.adapter = armyHeadListAdapter
    }

    override fun addListeners() {
        tvOk.setOnClickListener {
            onHeadClickListener?.onHeadClick(armyHeadListAdapter.getSelect())
            dismiss()
        }
        armyHeadListAdapter.setOnItemClickListener { adapter, view, position ->
            armyHeadListAdapter.setSelect(position)
        }
    }

    fun setIconData(list: List<ArmyIcon>) {
        armyHeadListAdapter.setNewInstance(list.toMutableList())
    }

    interface OnHeadClickListener {
        fun onHeadClick(icon: String)
    }

    fun setOnHeadClickListener(onHeadClickListener: OnHeadClickListener) {
        this.onHeadClickListener = onHeadClickListener
    }
}